package com.nanyang.tms.service.waybill.impl.flow;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.nanyang.common.core.flow.context.TransHandlerContext;
import com.nanyang.common.core.flow.convert.TransConvert;
import com.nanyang.common.core.flow.factory.AbstranctTransPipelineFactory;
import com.nanyang.common.core.flow.invoker.DefaultTransPipeline;
import com.nanyang.common.core.flow.invoker.TransPipeline;
import com.nanyang.tms.api.dto.request.waybill.WaybillShipmentAddRequest;
import com.nanyang.tms.domain.waybill.shipment.context.CheckSupplierNoContext;
import com.nanyang.tms.domain.waybill.shipment.context.WaybillShipmentAddContext;
import com.nanyang.tms.manager.cost.handler.CalculateCostFreightHandler;
import com.nanyang.tms.manager.waybill.handler.SaveTackInfoHandler;
import com.nanyang.tms.manager.waybill.handler.UpdateForecastHandler;
import com.nanyang.tms.manager.waybill.shipment.handler.CalculateSupplierWeightHandler;
import com.nanyang.tms.manager.waybill.shipment.handler.CheckSupplierNoHandler;
import com.nanyang.tms.manager.waybill.shipment.handler.SaveExpendHandler;
import com.nanyang.tms.manager.waybill.shipment.handler.SaveWaybillShipmentHandler;
import com.nanyang.tms.manager.waybill.shipment.handler.SendSupplierCodeHandler;
import com.nanyang.tms.manager.waybill.shipment.handler.UpdateShipmentHandler;
@Component
public class WaybillShipmentProcessPipelineFactory  extends AbstranctTransPipelineFactory<WaybillShipmentAddRequest>{
	@Autowired
	private  CheckSupplierNoHandler checkSupplierNoHandler;
	@Autowired
	private  CalculateSupplierWeightHandler calculateSupplierWeightHandler;
	@Autowired
	private CalculateCostFreightHandler calculateCostFreightHandler;
	@Autowired
	private SaveWaybillShipmentHandler saveWaybillShipmentHandler;
	@Autowired
	private UpdateShipmentHandler updateShipmentHandler;
	@Autowired
	private UpdateForecastHandler updateForecastHandler;
	@Autowired
	private SaveExpendHandler saveExpendHandler;
	@Autowired
	private SaveTackInfoHandler saveTackInfoHandler;
	@Autowired
	private SendSupplierCodeHandler  sendSupplierCodeHandler;
	@Override
	public TransHandlerContext createContext() {
		return new WaybillShipmentAddContext();
	}

	@Override
	public void doBuild(TransPipeline pipeline) {
		pipeline.addLast(checkSupplierNoHandler);//计算重量
		pipeline.addLast(calculateSupplierWeightHandler);//计算重量
		pipeline.addLast(calculateCostFreightHandler);//计算运费
		pipeline.addLast(false,saveWaybillShipmentHandler);//修改运单基本信息 ,插入收货材积信息
		pipeline.addLast(false, updateShipmentHandler);//修改出货总单的总实重、体积重、计费重插入收货单关系表&插入收货单关系表
		pipeline.addLast(false, updateForecastHandler);//修改预报单状态已出库
		pipeline.addLast(false, saveExpendHandler);//插入支出费用 
		pipeline.addLast(true, saveTackInfoHandler);//保存track信息
		pipeline.addLast(sendSupplierCodeHandler);
	}

	@Override
	public TransPipeline createPipeline(TransHandlerContext context) {
		return new DefaultTransPipeline(context,super.getDataSourceTransactionManager(),super.getTransactionDefinition()); 
	}

	@Override
	public TransConvert createConvert() {
		return new WaybillShipmentConvert();
	}

}
